from  models import simple_sql

from flask import current_app, g
from flask.cli import with_appcontext


def get_db():
    # 连接数据库
    if 'db' not in g:
        g.db = simple_sql(current_app.config['HOST'],current_app.config['USER'],current_app.config['PASSWORD'])
    return g.db


def close_db(e=None):
    # 关闭数据库
    db = g.pop('db', None)
    if db is not None:
        db.close_sql()